<template>
  <view class="demo-container">
    <!-- 基础用法 -->
    <view class="demo-block">
      <view class="demo-block__title">基础用法</view>
      <view class="demo-block__content">
        <fu-count-down :time="time" />
      </view>
    </view>
    
    <!-- 显示天数 -->
    <view class="demo-block">
      <view class="demo-block__title">显示天数</view>
      <view class="demo-block__content">
        <fu-count-down 
          :time="time" 
          show-days
          day-text="天"
          hour-text="时"
          minute-text="分"
          second-text="秒"
        />
      </view>
    </view>
    
    <!-- 手动控制 -->
    <view class="demo-block">
      <view class="demo-block__title">手动控制</view>
      <view class="demo-block__content">
        <fu-count-down 
          ref="countDown"
          :time="time"
          :auto-start="false"
          class="count-down"
        />
        <view class="button-group">
          <fu-button 
            type="primary"
            size="small"
            @click="start"
            class="button-item"
          >开始</fu-button>
          <fu-button 
            type="warning"
            size="small"
            @click="pause"
            class="button-item"
          >暂停</fu-button>
          <fu-button 
            type="info"
            size="small"
            @click="reset"
            class="button-item"
          >重置</fu-button>
        </view>
      </view>
    </view>
    
    <!-- 倒计时结束 -->
    <view class="demo-block">
      <view class="demo-block__title">倒计时结束</view>
      <view class="demo-block__content">
        <fu-count-down 
          :time="3000"
          @finish="onFinish"
        />
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      time: 30 * 60 * 1000 // 30分钟
    }
  },
  methods: {
    start() {
      this.$refs.countDown.start()
    },
    pause() {
      this.$refs.countDown.stop()
    },
    reset() {
      this.$refs.countDown.reset()
    },
    onFinish() {
      uni.showToast({
        title: '倒计时结束',
        icon: 'none'
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.demo-container {
  padding: 20rpx;
}

.demo-block {
  margin-bottom: 30rpx;
  
  &__title {
    margin-bottom: 20rpx;
    font-size: var(--fu-font-size-lg);
    color: var(--fu-text-color);
  }
  
  &__content {
    background-color: #fff;
    border-radius: var(--fu-radius-base);
    padding: 30rpx;
  }
}

.count-down {
  margin-bottom: 20rpx;
}

.button-group {
  display: flex;
  align-items: center;
}

.button-item {
  margin-right: 20rpx;
  
  &:last-child {
    margin-right: 0;
  }
}
</style> 